package org.fisco.bcos.asset.controller;


import java.math.BigInteger;
import java.util.List;

import org.fisco.bcos.asset.client.CharityDonationClient;
import org.fisco.bcos.asset.resp.ActiveProject;
import org.fisco.bcos.asset.resp.DonationRecord;
import org.fisco.bcos.asset.resp.DonationRecordItem;
import org.fisco.bcos.asset.resp.ProjectDetail;
import org.fisco.bcos.asset.service.parent.CharityService;
import org.fisco.bcos.sdk.abi.datatypes.generated.tuples.generated.Tuple3;
import org.fisco.bcos.sdk.abi.datatypes.generated.tuples.generated.Tuple7;
import org.fisco.bcos.sdk.transaction.model.exception.ContractException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 公共逻辑
 */
@RestController
@RequestMapping("/api/charity")
public class CharityController {


    @Qualifier("charityServiceImpl")
    @Autowired
    private CharityService charityService;

    @Resource
    private CharityDonationClient client;

    // 获取项目详情
    @GetMapping("/project/{projectId}")
    public ProjectDetail getProjectDetails(
            @PathVariable BigInteger projectId) {
        ProjectDetail projectDetails = charityService.getProjectDetails(projectId);
        return projectDetails;
    }
    // 获取捐赠记录
    @GetMapping("/project/{projectId}/donations")
    public List<DonationRecordItem> getDonationRecords(
            @PathVariable BigInteger projectId) {
        List<DonationRecordItem> donationRecords = charityService.getDonationRecords(projectId);
        return donationRecords;
    }
    // 获取角色信息
    @GetMapping("/user/{address}/role")
    public BigInteger getUserRole(@PathVariable String address) {
        return charityService.getUserRole(address);
    }
    // 获取项目数量
    @GetMapping("/project/count")
    public BigInteger getProjectCount() {
        return charityService.getProjectCount();
    }
    // 获取申请数量
    @GetMapping("/application/count")
    public BigInteger getApplicationCount() {
        return charityService.getApplicationCount();
    }
    // 获取合约地址
    @GetMapping("/contract/address")
    public String getContractAddress() {
        return charityService.getContractAddress();
    }
    // 获取慈善组织地址
    @GetMapping("/charity-org")
    public String getCharityOrg() {
        return charityService.getCharityOrg();
    }
    // 获取监管机构地址
    @GetMapping("/regulator")
    public String getRegulator() {
        return charityService.getRegulator();
    }

    @GetMapping("/getAllActiveProjects")
    public List<ActiveProject> getAllActiveProjects() throws ContractException {
        return client.getAllActiveProjects();
    }
}